import abc

from .metrics import MetricsCollector, get_metric_scalar_value


class ProgressCollector(MetricsCollector, abc.ABC):
    def __init__(self, *, progress_metric_name: str = 'step'):
        super().__init__()
        self.progress_metric_name = progress_metric_name

    # action

    def _get_progress(self) -> int | float:
        progress = self._get_metric_value(self.progress_metric_name)
        if progress is None:
            progress = 0
        progress = get_metric_scalar_value(progress)
        if progress is None:
            raise ValueError(f"Metric {self.progress_metric_name} is not a scalar!")
        return progress
